package  
{
	/**
	 * @author Leong Shi Yun Davina
	 */
	public class CommonMath 
	{
		public static const nGRAVITY:Number = 9.81;
		public static const nPI:Number = Math.PI;
		public static const uiMETER_TO_PIXEL_RATIO:uint = 15;
		
		public static const nTO_DEG:Number = nPI / 180;
		public static const nRIGHT_ANGLE_DEG:Number = 90;
		public static const nSTRAIGHT_LINE_DEG:Number = 180;
		
		public static const nTO_RAD:Number = 180 / nPI;
		public static const nRIGHT_ANGLE_RAD:Number = nRIGHT_ANGLE_DEG * nTO_RAD;
		public static const nSTRAIGHT_LINE_RAD:Number = nSTRAIGHT_LINE_DEG * nTO_RAD;
		
		public function CommonMath() 
		{
			
		}
		
		/**
		 * Takes in the frame rate and returns the change in time for every frame
		 * @param	frameRate:Number is the frame rate the application is running at
		 * @return	delta time as a Number
		 */
		public static function getDeltaTime(frameRate:Number):Number
		{
			return 1 / frameRate;
		}
		
		/**
		 * Generates a random number within the minimum value and and range defined by the user
		 * @param	iRange:int Total numbers to generate starting from the minimum value
		 * @param	iMinVal:int minimum value of a range of numbers.
		 * @return
		 */
		public static function generateRandomNumber(nStartNum:Number, nLastNum:Number):Number
		{
			var nRand:Number = Math.floor(Math.random() * nLastNum) + nStartNum;
			return nRand;
		}
		
		/**
		 * Gets 2 points and returns the distance between 2 points in 2D space.
		 *
		 * @param	nPosX1:Number is the x-coordinate of point 1.
		 * @param	nPosY1:Number is the y-coordinate of point 1.
		 * @param	nPosX2:Number is the x-coordinate of point 2.
		 * @param	nPosY2:Number is the y-coordinate of point 2.
		 * @return	returns the distance between 2 points as a number.
		 */
		public static function getDistance2DSquared(nPosX1:Number, nPosY1:Number, nPosX2:Number, nPosY2:Number):Number
		{
			return ((nPosX1 - nPosX2) * (nPosX1 - nPosX2)) + ((nPosY2 - nPosY1) * (nPosY2 - nPosY1));
		}
		
		/**
		 * Gets 2 points and returns the square distance between 2 points in 2D space.
		 *
		 * @param	nPosX1:Number is the x-coordinate of point 1.
		 * @param	nPosY1:Number is the y-coordinate of point 1.
		 * @param	nPosX2:Number is the x-coordinate of point 2.
		 * @param	nPosY2:Number is the y-coordinate of point 2.
		 * @return	returns the distance between 2 points as a number.
		 */
		public static function getDistance2D(nPosX1:Number, nPosY1:Number, nPosX2:Number, nPosY2:Number):Number
		{
			return Math.sqrt(((nPosX1 - nPosX2) * (nPosX1 - nPosX2)) + ((nPosY2 - nPosY1) * (nPosY2 - nPosY1)));
		}
		
		/**
		 * Gets 2 points and returns the distance between 2 points in 3D space.
		 *
		 * @param	nPosX1:Number is the x-coordinate of point 1.
		 * @param	nPosY1:Number is the y-coordinate of point 1.
		 * @param	nPosZ1:Number is the z-coordinate of point 1.
		 * @param	nPosX2:Number is the x-coordinate of point 2.
		 * @param	nPosY2:Number is the y-coordinate of point 2.
		 * @param	nPosZ2:Number is the z-coordinate of point 2.
		 * @return	returns the distance between 2 points as a number.
		 */
		public static function getDistance3DSquared(nPosX1:Number, nPosY1:Number, nPosZ1:Number, nPosX2:Number, nPosY2:Number, nPosZ2:Number):Number
		{
			return ((nPosX1 - nPosX2) * (nPosX1 - nPosX2)) + ((nPosY2 - nPosY1) * (nPosY2 - nPosY1)) + ((nPosZ2 - nPosZ1) * (nPosZ2 - nPosZ1));
		}
		
		/**
		 * Gets 2 points and returns the square distance between 2 points 3D space.
		 *
		  * @param	nPosX1:Number is the x-coordinate of point 1.
		 * @param	nPosY1:Number is the y-coordinate of point 1.
		 * @param	nPosZ1:Number is the z-coordinate of point 1.
		 * @param	nPosX2:Number is the x-coordinate of point 2.
		 * @param	nPosY2:Number is the y-coordinate of point 2.
		 * @param	nPosZ2:Number is the z-coordinate of point 2.
		 * @return	returns the distance between 2 points as a number.
		 */
		public static function getDistance3D(nPosX1:Number, nPosY1:Number, nPosZ1:Number, nPosX2:Number, nPosY2:Number, nPosZ2:Number):Number
		{
			return Math.sqrt(((nPosX1 - nPosX2) * (nPosX1 - nPosX2)) + ((nPosY2 - nPosY1) * (nPosY2 - nPosY1)) + ((nPosZ2 - nPosZ1) * (nPosZ2 - nPosZ1)));
		}
		
		/**
		 * Gets an angle in degrees and converts it to radians
		 * @param	nAngleDeg:Number is an angle in degrees
		 * @return  An angle in radians
		 */
		public static function degreeToRadian(nAngleDeg:Number):Number
		{
			return nAngleDeg * nTO_RAD;
		}
		
		/**
		 * Gets an angle in radians and converts it to degress
		 * @param	nAngleDeg:Number is an angle in radians
		 * @return  An angle in degrees
		 */
		public static function radianToDegree(nAngleRad:Number):Number
		{
			return nAngleRad * nTO_DEG;
		}
	}

}